﻿@model Matrix.MaKaYunShang.Model.MagUser

@{
    ViewBag.Title = "修改账号";
    ViewBag.PathToBtn = "/MagUser/List";
    ViewBag.TextBtn = "返回至账号管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!-- /.row -->
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                账号信息
            </div>
            <div class="panel-body">
                <div class="row">
                    @using (Html.BeginForm("Update", "MagUser", FormMethod.Post, new {id = "frmUpdate", enctype = "multipart/form-data"}))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)
                        
                        <div class="col-lg-12">
                            <fieldset>
                                @Html.HiddenFor(model => model.Id)
                                @Html.HiddenFor(model => model.AddTime)
                                @Html.HiddenFor(model => model.IsDelete)
                                @Html.HiddenFor(model => model.IsSuper)
                                @Html.HiddenFor(model => model.LastLoginIp)

                                @if (ViewBag.CurrentUserRoleId == 1)
                                {
                                    <div class="form-group col-md-6">
                                        <label>角色</label>
                                        <div class="input-group">
                                            @Html.DropDownList("RoleId", (IEnumerable<SelectListItem>) ViewBag.Roles, new {@class = "form-control"})
                                            <span class="input-group-addon"></span>
                                        </div>
                                    </div>
                                }
                                else
                                {
                                    @Html.HiddenFor(model => model.RoleId)
                                }

                                <div class="form-group col-md-6">
                                    <label>名称</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.RealName, new { @class = "form-control", placeholder = "显示名称" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>手机号</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.Mobile, new { @class = "form-control", placeholder = "手机号" })
                                        <span class="input-group-addon red">必填</span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>登录名</label>
                                    <div class="input-group">
                                        @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", @readonly = "readonly" })
                                        <span class="input-group-addon red"></span>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label>密码</label>
                                    <div class="input-group">
                                        @Html.PasswordFor(model => model.Pwd, new { @class = "form-control", placeholder = "为空则保留为原密码" })
                                        <span class="input-group-addon red"></span>
                                    </div>
                                </div>
                                
                                <div class="col-md-12">
                                    <button id="btnSave" type="submit" class="btn btn-primary">确认并保存</button>
                                </div>
                            </fieldset>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

@section javascript{
    <script type="text/javascript">
        $(function() {
            $("#frmUpdate").validate({
                rules: {
                    RealName: { required: true },
                    Mobile: {
                        required: true,
                        isMobile: true,
                        remote: {
                            url: "@Url.Action("ValidateMobile")",
                        dataType: "json",
                        type: "post",
                        data: { mobile: $('#Mobile').val(), userId: '@Model.Id' }
                    }
                    }
                },
                messages: {
                    RealName: { required: "请填写姓名" },
                    Mobile: { required: "请填写手机号", remote: "手机号已存在" }
                },
                submitHandler: function (form) {
                    form.submit();
                }
            });
        });

    </script>
}